// yb_mingpian/pages/member/upgrade/upgrade.js
var e = getApp(),
  a = e.requirejs("core"),
  r = e.requirejs("check");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperCurrent: 0,
    dl_level: 0
  },
  swiperChange: function (e) {
    console.log(e);
    this.setData({
      swiperCurrent: e.detail.current   //获取当前轮播图片的下标
    })
  },
  upgrade: function () {
    let that = this
    let level = Number(that.data.swiperCurrent) + 1 + Number(that.data.dl_level)
    console.log("level", level)
    a.get("User/UpLevel", {
      uid: getApp().getCache("userinfo").uid,
      level: level
    }, function (s) {
      console.log('接口调用111111111111111111', s)
      if (s.code == 0) {
        a.get("Pay/UpLevelPay", {
          uid: getApp().getCache("userinfo").uid,
          order_id: s.info,
          openid: getApp().getCache("userinfo").openid
        }, function (t) {
          console.log('===ceshi', t)
          !t.code ? (
            wx.requestPayment({
              'timeStamp': t.info.timeStamp,
              'nonceStr': t.info.nonceStr,
              'package': t.info.package,
              'signType': 'MD5',
              'paySign': t.info.paySign,
              'success': function (res) {
                if (res.errMsg == "requestPayment:ok") {
                  wx.setNavigationBarTitle({
                    title: "支付成功"
                  });
                  o.setData({
                    success: true,
                    "list.order_status": 1
                  });
                  a.get("Card/Getmycardid", {
                    uid: getApp().getCache("userinfo").uid,
                  }, function (res) {
                    console.log(res)
                    o.setData({
                      card_id1: res.card_id
                    })
                    wx.navigateTo({
                      // url: "/yb_mingpian/pages/cardinfo/ceshi1?card_id1=" + o.data.card_id1
                      url: "yb_mingpian/pages/member/index/index"
                    })
                  })

                  o.hideModal_1();
                  o.onLoad();
                  o.onShow();
                  o.hideModal_1();
                  //推送
                  a.get('Wxpush/PayOrderPush', {
                    out_trade_no: o.data.list.out_trade_no,
                    formid: o.data.formid,
                    uid: getApp().getCache("userinfo").uid
                  }, function (t) {
                    console.log(t)
                  });
                } else {
                  a.alert('支付失败！')
                  // wx.redirectTo({
                  //   url: "/yb_mingpian/pages/cardinfo/ceshi"
                  // })
                }
              },
              'fail': function (res) {
                a.alert('您已经取消支付！')
                // wx.redirectTo({
                //   url: "/yb_mingpian/pages/cardinfo/ceshi"
                // })
              }
            })
          ) : (a.alert(t.msg), setTimeout(function () {
            console.log('======测试')
            wx.navigateBack()
          }, 1e3))
        })
      } else if (s.code == 1) {
        wx.showToast({
          title: s.msg,
          icon: 'none'
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    a.get("User/Userinfo", {
      uid: getApp().getCache("userinfo").uid,
    }, function (t) {
      console.log(t)
      that.setData({
        dl_level: t.info.dl_level
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})